<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2024/8/12
 * Time: 16:05
 */

namespace app\common\cachemodel\zl8;

use app\common\model\BaseCache;
use XznsTools\cache\CacheManage;

class Zl8AstrChatBusyDateRecord extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zl8_astr_chat_busy_date_record';
    protected $cacheModel = 'voice_consult.reservation_date_busy';

    /**
     * 获取用户预约列表
     * @param $astrId
     * @return array|mixed
     * @throws \Exception
     */
    public function getAstrDateBusyList($astrId)
    {
        return CacheManage::getInstance()->setCacheConfig($this->cacheModel, $astrId)->ZsGetIocData('list', function () use ($astrId)
        {
            try
            {
                return $this->where('astr_id', $astrId)->column('date', 'id');
            }
            catch (\Exception $e)
            {
                \think\Log::write(__CLASS__ . ' => ' . __FUNCTION__ . '()异常：' . $e->getMessage() . '失败信息：' . $e->getFile() . ':' . $e->getLine(), 'error', true);
                return [];
            }
        }, true);
    }


    public function saveData($data)
    {
        try
        {
            $id = $this->insertAll($data);
            $cacheModel = CacheManage::getInstance();
            foreach ($data as $datum)
            {
                $cacheModel->setCacheConfig($this->cacheModel, $datum['astr_id'])->rmCache('list');
            }
        }
        catch (\Exception $e)
        {
            \think\Log::write(__CLASS__ . ' => ' . __FUNCTION__ . '()异常：' . $e->getMessage() . '失败信息：' . $e->getFile() . ':' . $e->getLine(), 'error', true);
            $id = 0;
        }
        return $id;
    }

    public function delData($astrId)
    {
        try
        {
            $this->where('astr_id', $astrId)->delete();
            CacheManage::getInstance()->setCacheConfig($this->cacheModel, $astrId)->rmCache('list');
        }
        catch (\Exception $e)
        {
            \think\Log::write(__CLASS__ . ' => ' . __FUNCTION__ . '()异常：' . $e->getMessage() . '失败信息：' . $e->getFile() . ':' . $e->getLine(), 'error', true);
            return false;
        }
        return true;
    }
}
